package com.jhgk.jhcee.app.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.jhgk.jhcee.app.domain.model.MProvinceScoreWcModel;
import com.jhgk.jhcee.app.service.MProvinceScoreWcService;
import com.jhgk.jhcee.common.enums.BasisResultEnum;
import com.jhgk.jhcee.common.resultful.PageResultful;
import com.jhgk.jhcee.jhgk.mapper.MProvinceScoreWcMapper;
import com.jhgk.jhcee.jhgk.model.MProvinceScoreWc;
import com.jhgk.jhcee.jhgk.model.MProvinceScoreWcExample;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: xiezhongping
 * @description:
 * @date: 2021/8/13 14:28.
 */
@Service(value = "MProvinceScoreWcServiceImpl")
public class MProvinceScoreWcServiceImpl implements MProvinceScoreWcService {

    @Autowired
    MProvinceScoreWcMapper mProvinceScoreMapper;

    @Override
    public PageResultful<PageInfo<MProvinceScoreWc>> searchAllPage(MProvinceScoreWcModel model) {
        if (null == model) {
            return PageResultful.fail(BasisResultEnum.PARAM_IS_NULL);
        }
        MProvinceScoreWcExample example = new MProvinceScoreWcExample();
        MProvinceScoreWcExample.Criteria criteria = example.createCriteria();
        criteria.andProvinceUuidEqualTo(model.getProvinceUuid());
        criteria.andYearEqualTo(model.getYear());
        PageHelper.startPage(model.getPage(),model.getLimit());
        List<MProvinceScoreWc> mProvinceScores = mProvinceScoreMapper.selectByExample(example);
        if (mProvinceScores.isEmpty()){
            return PageResultful.fail(BasisResultEnum.QUERY_IS_NULL);
        }
        return PageResultful.success(new PageInfo<>(mProvinceScores));
    }
}
